﻿using System.Collections.Generic;
using System.Linq;
using Model;

namespace ReportBrowser.ViewModel
{
    internal class MessageContainerTypeViewModel : TypeViewModel
    {
        #region Lifecycle

        public MessageContainerTypeViewModel(Type model, ActualEntities context)
            : base(model, context) { }

        #endregion Lifecycle

        #region Properties

        public static bool IsCummulative { get; set; }

        public IEnumerable<MessageViewModel> Messages
        {
            get
            {
                return MessageViewModel.FindByType(this.Model.ModuleAssemblyName, this.Model.ModuleName,
                    this.Model.NamespaceName, this.Model.Name, IsCummulative);
            }
        }

        public double Weight
        {
            get
            {
                return this.Messages.Sum(mvm => mvm.Weight);
            }
        }

        #endregion Properties

        #region Methods

        /// <summary>
        /// Gets a value wether any message corresponding to the given type has been instantiadted, or not.
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool HasMessages(Type model)
        {
            return MessageViewModel.IsAnyByType(model.ModuleAssemblyName, model.ModuleName,
                model.NamespaceName, model.Name, IsCummulative);
        }

        #endregion Methods
    }
}
